package main

import "fmt"

//求两个数的和
func sumFn(x int, y int) int {
	sum := x + y
	return sum
}

//求两个数的差
func subFn(x int, y int) int {
	sum := x - y
	return sum
}

//函数参数的简写
func subFn1(x, y int) int {
	sum := x - y
	return sum
}

//函数的可变参数，可变参数是指函数的参数数量不固定。Go 语言中的可变参数通过在参数名后加...来标识
func sumFn1(x ...int) int {
	//fmt.Printf("%v -- %T\n", x, x)	//[12 33 454 66 77] -- []int
	sum := 0
	for _, v := range x {
		sum += v
	}
	return sum
}

func sumFn2(x int, y ...int) int {
	//fmt.Printf("%v -- %T\n", x, x)	//[12 33 454 66 77] -- []int
	sum := x
	for _, v := range y {
		sum += v
	}
	return sum
}

func main() {
	//sum1 := sumFn(12, 3)
	//fmt.Println(sum1) //15
	//
	//sum2 := sumFn(15, 5)
	//fmt.Println(sum2) //20

	//a := 10
	//b := 5
	//sub1 := subFn(a, b)
	//fmt.Println(sub1)	//5

	//sub2 := subFn1(22, 4)
	//fmt.Println(sub2)	//18

	//sum3 := sumFn1(12, 33, 454, 66, 77)
	//fmt.Println(sum3)

	//sum4 := sumFn1(1, 2, 3, 4, 5)
	//fmt.Println(sum4)

	sum5 := sumFn2(100, 1, 2, 3, 4, 5)
	fmt.Println(sum5)
}
